package pogo;

public class Game {

    //将对象作为了一个属性
    Person person=new Person();
    Computer computer=new Computer();
    int count=0;

    public static void main(String[] args) {
        Game game=new Game();
    }
    public Game(){
        starGame();
        getResult();
    }

//    开始游戏 1-石头 2-剪刀 3-布
    public void starGame(){
        System.out.println("游戏开始");
        System.out.println(person.name+"----VS----"+computer.name);
        for (int i = 0; i < 5; i++) {
            System.out.println("当前是第"+(i+1)+"轮");
//            出拳
            int person1=this.person.chuQuan();
            int computer1=this.computer.chuQuan();
            /*
            * 判断出拳胜负*/
            if((person1==1&&computer1==2)||(person1==2&&computer1==3)||(person1==3&&computer1==1)){
//                玩家胜利
                System.out.println(this.person.name+"胜利");
                this.person.score=this.person.score+1;//胜利加一分
            }else if((person1==2&&computer1==1)||(person1==3&&computer1==2)||(person1==1&&computer1==3)){
//                人机胜利
                System.out.println(this.computer.name+"胜利");
                this.computer.score=this.computer.score+1;//胜利加一分
            }else if(computer1==person1){
                System.out.println("好巧哦，平局啦");
            }else if(person1==0){
                System.out.println(this.person.name+"出错啦扣一分");
                this.person.score=this.person.score-1;
            }else if(computer1==0){
                System.out.println(this.computer.name+"出错啦扣一分");
                this.computer.score=this.computer.score-1;
            }
            System.out.println("当前玩家分数为："+person.score+"电脑分数为："+computer.score);
            getResult();
        }
    }
//    判断输赢
    public void getResult(){
        System.out.println("----最终玩家分数为："+person.score+"电脑分数为："+computer.score+"----");
        if(person.score>computer.score){
            System.out.println("最终的获胜者是"+person.name);
        }else if(person.score<computer.score){
            System.out.println("最终的获胜者是"+computer.name);
        }else{
            System.out.println("天哪竟然和局啦");
        }
        System.out.println("------游戏结束------");
    }

}
